<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>testPost2</title>
</head>
<body>
    <!--构造body为json格式的数据就只能使用ajax的方式来实现-->
    <button onclick="sendJson()">发送请求</button>
    <script src="https://lib.baomitu.com/jquery/3.6.0/jquery.min.js"></script>
    <script>
        function sendJson(){
            let body = {
                userId : 100,
                classId : 1
            };
            $.ajax({
                type: "post",
                url: "postParameter",
                contentType : "application/json;charset=utf-8",
                data: JSON.stringify(body),
                success:function(data,status){
                    console.log(body);
                }
            })
        }
    </script>
</body>
</html>